<script type="text/javascript">
$(function() {ldelim}
        $("#home-products").sortable({ldelim}
            update: function(event, ui) {ldelim}
            $.post("controller.php?task=sorthomepage",{ldelim} products: $('#home-products').sortable('serialize'){rdelim} );
         {rdelim}
{rdelim});
    	$( "#sortable" ).disableSelection();
{rdelim});

    function addhomepageproduct(){ldelim}
           var txtitemcode = $("#txtitemcode").val();
         if(txtitemcode=='')
             {ldelim}
                     alert("Item code cannot be empty");
                     $("#txtitemcode").focus();
                     return false;
             {rdelim}

          $("#loader_area").show();
		$("#loader_area").html('<img src="images/shared/loader.gif" /> loading...');
		$.ajax({ldelim}
		type: "POST",
		url: 'controller.php?task=addhomepageproduct',
                data: ({ldelim}itemcode:txtitemcode {rdelim}),
    	success: function(data, textStatus, XMLHttpRequest){ldelim}
    	   	if(data != '') {ldelim}
                   if(data!='F')
                       {ldelim}
                       alert("successfully updated the home page products");
                        $("#message_area").show();
	    	   	$("#message_area").html(data);
                      loadPage('product/homepageproduct');
                      {rdelim}
                    else{ldelim}
                          alert("Item code not exist or product id out of stock ");
                          loadPage('product/homepageproduct');
                    {rdelim}
    	   	{rdelim}
    	{rdelim},
    	complete: function complete(XMLHttpRequest, textStatus){ldelim}
            //$("#loader_area").hide();
        {rdelim}
	{rdelim});
{rdelim}
function deletehomepageproduct(productid)
{ldelim}
	var msg = confirm("Are you sure you want to remove this product from the homepage");
	if (msg){ldelim}
		$.ajax({ldelim}
			type: "POST",
			url: 'controller.php?task=deletehomepageproduct',
			data: ({ldelim}productid: productid{rdelim}),
	    	success: function(data, textStatus, XMLHttpRequest){ldelim}
	    	   	if(data != '') {ldelim}
                             alert("successfully deleted the product");
	    			$("#message_area").html(data);
	    			loadPage('product/homepageproduct');
	    	   	{rdelim}
	    	{rdelim},
	    	complete: function complete(XMLHttpRequest, textStatus){ldelim}
	            //$("#loader_area").hide();
	       {rdelim}
		{rdelim});
	{rdelim} else {ldelim}
		return false;
	{rdelim}
{rdelim}
</script>
<div id="page-heading">
	<h1>{$title}</h1>         
</div>

<div id="page-heading">
	Item code  : <input onblur="" type="text" name="txtitemcode" id="txtitemcode"> <input onclick="addhomepageproduct()" type="button" value="add" id="add" name="add">
</div>

<ul id="home-products" class="ui-sortable">
	{section name=sec1 loop=$itemcodearr}
		<li id="product_{$itemcodearr[sec1].productid}" class="ui-state-default">
                <span class="ui-icon ui-icon-arrowthick-2-n-s">
                </span>
         <img src="{$siteurl}/images/products/thumbs/{$itemcodearr[sec1].filename}" border="0" width="75" height="75" >
       <strong>{$itemcodearr[sec1].product_title}</strong>
           {$itemcodearr[sec1].itemcode}
       <a  href="javascript: void(0);" onclick="deletehomepageproduct({$itemcodearr[sec1].productid});"><img align="right" src="images/icons/a-minus.gif" /></a>
                </li>
	{/section}
</ul>	